#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import Any

from cta.interface.action.print.abstract_print_action import AbstractPrintAction
from web.constants.datetime_format import DatetimeFormat
from web.domain.maximum_drawdown import MaximumDrawDown
from web.domain.responsibility_chain_dto import ResponsibilityChainDto
from web.manager.log_manager import LogManager
from web.util.datetime_util import DatetimeUtil

Logger = LogManager.get_logger(__name__)

class MaximumDrawDownPrintAction(AbstractPrintAction):
    """
    打印最大回撤动作
    """

    def exec(self, responsibility_chain_dto: ResponsibilityChainDto = None):
        Logger.info("打印最大回撤动作")

        maximum_drawdown_list: list[MaximumDrawDown] = self.quant2_account_log_dao.calculate_maximum_drawdown()
        if maximum_drawdown_list is not None and len(maximum_drawdown_list) > 0:
            for maximum_drawdown in maximum_drawdown_list:
                Logger.info("quant2最大回撤：%f，开始时间：%s，结束时间：%s，账号：%s", maximum_drawdown.maximum_drawdown,
                            DatetimeUtil.datetime_to_str(maximum_drawdown.date1, DatetimeFormat.Date_Format),
                            DatetimeUtil.datetime_to_str(maximum_drawdown.date2, DatetimeFormat.Date_Format),
                            maximum_drawdown.account_name)

        maximum_drawdown_list = self.optimize2_account_log_dao.calculate_maximum_drawdown()
        if maximum_drawdown_list is not None and len(maximum_drawdown_list) > 0:
            for maximum_drawdown in maximum_drawdown_list:
                Logger.info("optimize2最大回撤：%f，开始时间：%s，结束时间：%s，账号：%s", maximum_drawdown.maximum_drawdown,
                            DatetimeUtil.datetime_to_str(maximum_drawdown.date1, DatetimeFormat.Date_Format),
                            DatetimeUtil.datetime_to_str(maximum_drawdown.date2, DatetimeFormat.Date_Format),
                            maximum_drawdown.account_name)

        super().exec(responsibility_chain_dto)